package com.yenlien.traceyun.plant.dao;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.plant.entity.ColdStorageComp;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ColdStorageCompDao extends BaseJpaDao<ColdStorageComp> {

    List<ColdStorageComp> findByState(String state);

    @Query(value = "SELECT * FROM t_cold_storage_comp WHERE comp_type IS NULL AND state = '1'", nativeQuery = true)
    List<ColdStorageComp> findAllComp();


    @Query(value = "SELECT tcsc.id, count(tcs.id) coldNum, tcsc.`name`, tcsc.address, tcsc.coordinate, tcsc.cold_img, tcsc.phone, tcsc.principal  FROM t_cold_storage_comp tcsc LEFT JOIN t_cold_storage tcs ON tcsc.id = tcs.company_id " +
            "WHERE tcsc.comp_type IS NULL AND tcsc.state = '1' GROUP BY tcsc.id", nativeQuery = true)
    List<JSONObject> findComp();





    List<ColdStorageComp> findByIdAndState(String id, String state);

    @Query(value = "SELECT COUNT(id) FROM t_cold_storage_comp", nativeQuery = true)
    String countNum();

    ColdStorageComp getById(String id);
}
